home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / twnsck12.zip / SRC\BUILD.SH < prev    next >
Linux/UNIX/POSIX Shell Script  |  1994-12-04  |  3KB  |  146 lines

  1. #!/bin/sh
  2. # Remove all carriage returns and Control-Zs
  3. rm -f a.out test.c
  4. rm -f *.o tshost
  5. echo "Cleaning the source code of MS-DOS control characters"
  6. for i in *.c *.h
  7. do
  8.     tr -d '\015\032' < $i > tempfile
  9.     mv tempfile $i
  10. done
  11.  
  12. # Test for a few things we need to know about
  13.  
  14. echo "Testing for sys/select.h"
  15. if [ -f /usr/include/sys/select.h ]
  16. then
  17.     SELECT_H=-DNEED_SELECT_H
  18.     echo "You have sys/select.h"
  19. fi
  20.  
  21. echo "Testing for sys/ttold.h"
  22. if [ -f /usr/include/sys/ttold.h ]
  23. then
  24.     TTOLD_H=-DNEED_TTOLD_H
  25.     echo "You have sys/ttold.h"
  26. fi
  27.  
  28. echo "Testing for sgtty.h"
  29. if [ -f /usr/include/sgtty.h ]
  30. then
  31.     echo "You have it"
  32. else
  33.     echo "You don't have it - I will use ioctl.h instead"
  34.     SGTTY_H=-DNO_SGTTY_H
  35. fi
  36.  
  37. # Try to find a C compiler that does ANSI.
  38. # Note that just testing for no error exit is not sufficient
  39. # because what we find may not be a compiler, so we test for
  40. # an a.out file.
  41.  
  42. echo "main(int argc, char **argv) { return (int) argv[argc]; }" > test.c
  43. echo "Attempting to find a compiler that will work"
  44. for i in bsdcc ucbcc cc acc gcc /usr/local/bin/gcc
  45. do
  46.     ( $i test.c ) </dev/null >/dev/null 2>&1
  47.     if [ -f a.out ]
  48.     then
  49.         CC=$i
  50.         break
  51.     fi
  52. done
  53.  
  54. case "$CC" in
  55. "")
  56.     echo "Unable to find an ANSI C compiler"
  57.     exit 1
  58.     ;;
  59. esac
  60.  
  61. echo "Using $CC as the C compiler"
  62.  
  63. echo "main() {}" > test.c
  64.  
  65. echo "Testing for -lsocket"
  66. if $CC test.c -lsocket > /dev/null 2>/dev/null
  67. then
  68.     echo "You will need -lsocket"
  69.     L_SOCKET=-lsocket
  70. else
  71.     echo "You don't need it"
  72. fi
  73.  
  74. echo "Testing for -lresolv"
  75. if $CC test.c -lresolv ${L_SOCKET} > /dev/null 2>/dev/null
  76. then
  77.     echo "You will need -lresolv"
  78.     L_RESOLV=-lresolv
  79. else
  80.     if [ -f /lib/resolv.so ]
  81.     then
  82.         echo "Found the resolver libraries in /lib/resolv.so"
  83.         L_RESOLV=/lib/resolv.so
  84.     else
  85.         if [ -f /usr/lib/resolv.so ]
  86.         then
  87.             echo "Found the resolver libraries in /usr/lib/resolv.so"
  88.             L_RESOLV=/usr/lib/resolv.so
  89.         else
  90.             echo "You don't appear to need resolver libraries"
  91.         fi
  92.     fi
  93. fi
  94.  
  95. echo "Testing for -lnsl"
  96. if $CC test.c -lnsl ${L_RESOLV} -lresolv ${L_SOCKET} > /dev/null 2>/dev/null
  97. then
  98.     echo "You will need -lnsl"
  99.     L_NSL=-lnsl
  100. else
  101.     echo "You don't appear to need -lnsl"
  102. fi
  103.  
  104. echo "main() {char *pch1, *pch2; memcpy(pch1, pch2, 10); memset(pch1, 0, 10); }" > test.c
  105. if $CC test.c > /dev/null 2>&1
  106. then
  107.     echo "You have memcpy and memset"
  108. else
  109.     echo "We will use TwinSock's memcpy and memset"
  110.     NEED_MEM=mem.o
  111. fi
  112.  
  113. echo "Testing for h_errno"
  114. echo "#include <netdb.h>
  115. main() { return h_errno; }" > test.c
  116. if $CC test.c > /dev/null 2>&1
  117. then
  118.     echo "h_errno is where it should be"
  119. else
  120.     echo "extern int h_errno; main() { return h_errno; }" > test.c
  121.     if $CC test.c > /dev/null 2>&1
  122.     then
  123.         echo "h_errno is not declared in netdb.h, but exists"
  124.         H_ERRNO=-DNEED_H_ERRNO
  125.     else
  126.         echo "h_errno does not exist, using errno"
  127.         H_ERRNO=-DNO_H_ERRNO
  128.     fi
  129. fi
  130.  
  131. rm -f a.out test.c
  132.  
  133. OBJECTS="tshost.o packet.o commands.o term.o $NEED_MEM"
  134.  
  135. echo "Building makefile"
  136. echo ".c.o:" > Makefile
  137. echo "    ${CC} ${SELECT_H} ${TTOLD_H} ${SGTTY_H} ${H_ERRNO} -c "'$*.c' >> Makefile
  138. echo >> Makefile
  139. echo "tshost: ${OBJECTS}" >> Makefile
  140. echo "    ${CC} -o tshost ${OBJECTS} ${L_NSL} ${L_RESOLV} ${L_SOCKET}" >> Makefile
  141.  
  142. echo
  143. echo 'Running "make"'
  144. echo
  145. exec make
  146.